package com.ruoyi.system.service.impl.fxImpl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.FxDistributionSetting;
import com.ruoyi.system.mapper.fx.FxDistributionSettingMapper;
import com.ruoyi.system.service.fx.IFxDistributionSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * 分销比例设置Service业务层处理
 *
 * @author ruoyi
 * @date 2024-09-12
 */
@Service
public class FxDistributionSettingServiceImpl implements IFxDistributionSettingService {
    @Autowired
    private FxDistributionSettingMapper fxDistributionSettingMapper;

    /**
     * 查询分销比例设置
     *
     * @param id 分销比例设置主键
     * @return 分销比例设置
     */
    @Override
    public FxDistributionSetting selectFxDistributionSettingById(Long id) {
        return fxDistributionSettingMapper.selectFxDistributionSettingById(id);
    }

    /**
     * 查询分销比例设置列表
     *
     * @param fxDistributionSetting 分销比例设置
     * @return 分销比例设置
     */
    @Override
    public List<FxDistributionSetting> selectFxDistributionSettingList(FxDistributionSetting fxDistributionSetting) {
        return fxDistributionSettingMapper.selectFxDistributionSettingList(fxDistributionSetting);
    }

    /**
     * 查询分销提成比例
     * @return
     */
    @Override
    public FxDistributionSetting selectFxDistributionRatio() {
        return fxDistributionSettingMapper.selectFxDistributionRatio();
    }

    /**
     * 新增分销比例设置
     *
     * @param fxDistributionSetting 分销比例设置
     * @return 结果
     */
    @Override
    public int insertFxDistributionSetting(FxDistributionSetting fxDistributionSetting) {
        fxDistributionSetting.setCreateTime(DateUtils.getNowDate());
        fxDistributionSetting.setCreateBy(SecurityUtils.getUsername());
        return fxDistributionSettingMapper.insertFxDistributionSetting(fxDistributionSetting);
    }

    /**
     * 修改分销比例设置
     *
     * @param fxDistributionSetting 分销比例设置
     * @return 结果
     */
    @Override
    @Transactional
    public void updateFxDistributionSetting(FxDistributionSetting fxDistributionSetting) {
        // 修改启用比例为禁用
        fxDistributionSettingMapper.updateFxDistribution();

        fxDistributionSetting.setUpdateBy(SecurityUtils.getUsername());
        fxDistributionSetting.setUpdateTime(DateUtils.getNowDate());
        fxDistributionSettingMapper.updateFxDistributionSetting(fxDistributionSetting);
    }

    /**
     * 批量删除分销比例设置
     *
     * @param ids 需要删除的分销比例设置主键
     * @return 结果
     */
    @Override
    public int deleteFxDistributionSettingByIds(Long[] ids) {
        return fxDistributionSettingMapper.deleteFxDistributionSettingByIds(ids);
    }

    /**
     * 删除分销比例设置信息
     *
     * @param id 分销比例设置主键
     * @return 结果
     */
    @Override
    public int deleteFxDistributionSettingById(Long id) {
        return fxDistributionSettingMapper.deleteFxDistributionSettingById(id);
    }
}
